/********************************************
 * 功能说明: 
 * 模块名称: 
 * 系统名称: 
 * 软件版权: 北京银杉金服科技有限公司
 * 系统版本: 1.0.0
 * 开发人员: zhangfb
 * 开发时间: 2018/9/9 1:02
 * 审核人员: 
 * 相关文档: 
 * 修改记录: 修改日期 修改人员 修改说明
 *********************************************//*

package com.hyacinth.security;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.AccessDecisionManager;
import org.springframework.security.access.SecurityMetadataSource;
import org.springframework.security.access.intercept.AbstractSecurityInterceptor;
import org.springframework.security.access.intercept.InterceptorStatusToken;
import org.springframework.security.web.FilterInvocation;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.servlet.*;
import java.io.IOException;

*/
/**
 * @author zhangfb
 * @version 1.0.0.1
 * @since JDK 1.8
 *//*

@Slf4j
@Component
public class CustomSecurityFilter extends AbstractSecurityInterceptor implements Filter {

    private final CustomSecurityMetadataSource customSecurityMetadataSource;

    private final AccessDecisionManager accessDecisionManager;

    @Autowired
    public CustomSecurityFilter(CustomSecurityMetadataSource customSecurityMetadataSource,
                                AccessDecisionManager accessDecisionManager) {
        this.customSecurityMetadataSource = customSecurityMetadataSource;
        this.accessDecisionManager = accessDecisionManager;
    }

    @PostConstruct
    public void init() {
        log.info("CustomSecurityFilter init ------------》》》");
        setAccessDecisionManager(accessDecisionManager);
    }


    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        FilterInvocation fi = new FilterInvocation(request, response, chain);
        invoke(fi);
    }

    private void invoke(FilterInvocation fi) throws IOException, ServletException {
        System.out.println("filter..........................");
        InterceptorStatusToken token = super.beforeInvocation(fi);
        try {
            fi.getChain().doFilter(fi.getRequest(), fi.getResponse());
        } finally {
            super.afterInvocation(token, null);
        }

    }

    @Override
    public SecurityMetadataSource obtainSecurityMetadataSource() {
        log.info("customSecurityFilter obtainSecurityMetadataSource >>>>>>>>>>>");
        return customSecurityMetadataSource;
    }

    @Override
    public Class<?> getSecureObjectClass() {
        return FilterInvocation.class;
    }

    @Override
    public void destroy() {
        log.info("customSecurityFilter filter destroy >>>>>>>>>>>");
    }

    @Override
    public void init(FilterConfig filterconfig) throws ServletException {
        log.info("customSecurityFilter filter init >>>>>>>>>>>");
    }

}
*/
